home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / ANSI Headers / streambuf < prev    next >
Encoding:
Text File  |  1994-12-27  |  4.3 KB  |  156 lines  |  [TEXT/MMCC]

  1. // streambuf standard header
  2. #ifndef _STREAMBUF_
  3. #define _STREAMBUF_
  4. #include <ios>
  5.  
  6. #if __MWERKS__
  7. #pragma options align=mac68k
  8. #endif
  9.  
  10.         // macros
  11. #define EOF    (-1)
  12.         // type streamoff
  13. typedef long streamoff;
  14. const streamoff _BADOFF = -1;
  15.         // class streampos
  16. class streampos {
  17. public:
  18.     streampos(streamoff = 0, const _Fpost * = 0);
  19.     streamoff offset() const;
  20.     streamoff operator-(const streampos&) const;
  21.     streampos& operator+=(streamoff _O)
  22.         {_Pos += _O; return (*this); }
  23.     streampos& operator-=(streamoff _O)
  24.         {_Pos -= _O; return (*this); }
  25.     streampos operator+(streamoff _O) const
  26.         {streampos s = *this; s += _O; return s; }
  27.     streampos operator-(streamoff _O) const
  28.         {streampos s = *this; s -= _O; return s; }
  29.     _Bool operator==(const streampos&) const;
  30.     _Bool operator!=(const streampos& _R) const
  31.         {return (!(*this == _R)); }
  32.     _Fpost *_Fpos()
  33.         {return (&_Fp); }
  34. private:
  35.     streamoff _Pos;
  36.     _Fpost _Fp;
  37.     };
  38.         // class streambuf
  39. class streambuf {
  40. public:
  41.     virtual ~streambuf();
  42.     virtual int showmany();
  43.     streampos pubseekoff(streamoff _O, ios::seekdir _W,
  44.         ios::openmode _M = ios::in | ios::out)
  45.         {return (seekoff(_O, _W, _M)); }
  46.     streampos pubseekoff(streamoff _O, ios::seek_dir _W,
  47.         ios::open_mode _M)
  48.         {return (pubseekoff(_O, (ios::seekdir)_W, (ios::openmode)_M)); }
  49.     streampos pubseekpos(streampos _P,
  50.         ios::openmode _M = ios::in | ios::out)
  51.         {return (seekpos(_P, _M)); }
  52.     streampos pubseekpos(streampos _P, ios::open_mode _M)
  53.         {return (seekpos(_P, (ios::openmode)_M)); }
  54.     streambuf *pubsetbuf(char *_S, int _N)
  55.         {return (setbuf(_S, _N)); }
  56.     int pubsync()
  57.         {return (sync()); }
  58.     int sbumpc()
  59.         {return (gptr() != 0 && gptr() < egptr()
  60.             ? *_Gn()++ : uflow()); }
  61.     int sgetc()
  62.         {return (gptr() != 0 && gptr() < egptr()
  63.             ? *_Gn() : underflow()); }
  64.     int sgetn(char *_S, int _N)
  65.         {return (xsgetn(_S, _N)); }
  66.     int snextc()
  67.         {return (sbumpc() == EOF ? EOF : sgetc()); }
  68.     int sputbackc(char _C)
  69.         {return (gptr() != 0 && eback() < gptr()
  70.             && _C == gptr()[-1]
  71.             ? *--_Gn() : pbackfail((unsigned char)_C)); }
  72.     int sungetc()
  73.         {return (gptr() != 0 && eback() < gptr()
  74.             ? *--_Gn() : pbackfail()); }
  75.     int sputc(int _C)
  76.         {return (pptr() != 0 && pptr() < epptr()
  77.             ? (*_Pn()++ = _C) : overflow(_C)); }
  78.     int sputn(const char *_S, int _N)
  79.         {return (xsputn(_S, _N)); }
  80.     int in_avail()
  81.         {return (gptr() != 0 && gptr() < egptr()
  82.             ? egptr() - gptr() : showmany()); }
  83. protected:
  84.     streambuf()
  85.         {_Init(); }
  86.     streambuf(ios::_Uninitialized)
  87.         {}
  88.     char *eback() const
  89.         {return (*_IGbeg); }
  90.     char *gptr() const
  91.         {return (*_IGnext); }
  92.     char *egptr() const
  93.         {return (*_IGend); }
  94.     void gbump(int _N)
  95.         {*_IGnext += _N; }
  96.     void setg(char *_B, char *_N, char *_E)
  97.         {*_IGbeg = _B, *_IGnext = _N, *_IGend = _E; }
  98.     char *pbase() const
  99.         {return (*_IPbeg); }
  100.     char *pptr() const
  101.         {return (*_IPnext); }
  102.     char *epptr() const
  103.         {return (*_IPend); }
  104.     void pbump(int _N)
  105.         {*_IPnext += _N; }
  106.     void setp(char *_B, char *_E)
  107.         {*_IPbeg = _B, *_IPnext = _B, *_IPend = _E; }
  108.     void setp(char *_B, char *_N, char *_E)
  109.         {*_IPbeg = _B, *_IPnext = _N, *_IPend = _E; }
  110.     unsigned char *&_Gn()
  111.         {return ((unsigned char *&)*_IGnext); }
  112.     unsigned char *&_Pn()
  113.         {return ((unsigned char *&)*_IPnext); }
  114.     virtual int overflow(int = EOF);
  115.     virtual int pbackfail(int = EOF);
  116.     virtual int underflow();
  117.     virtual int uflow();
  118.     virtual int xsgetn(char *, int);
  119.     virtual int xsputn(const char *, int);
  120.     virtual streampos seekoff(streamoff, ios::seekdir,
  121.         ios::openmode = ios::in | ios::out);
  122.     virtual streampos seekpos(streampos,
  123.         ios::openmode = ios::in | ios::out);
  124.     virtual streambuf *setbuf(char *, int);
  125.     virtual int sync();
  126.     void _Init();
  127.     void _Init(char **, char **, char **, char **, char **,
  128.         char **);
  129. private:
  130.     streambuf(const streambuf&); // undefined
  131.     streambuf& operator=(const streambuf&); // undefined
  132.     char *_Gbeg, *_Gnext, *_Gend;
  133.     char *_Pbeg, *_Pnext, *_Pend;
  134.     char **_IGbeg, **_IGnext, **_IGend;
  135.     char **_IPbeg, **_IPnext, **_IPend;
  136.     };
  137.  
  138. #if __MWERKS__
  139. #pragma options align=reset
  140. #endif
  141.  
  142. #endif
  143.  
  144. /*
  145.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  146.  * Consult your license regarding permissions and restrictions.
  147.  */
  148.  
  149. /* Change log:
  150.  *94June04 PlumHall baseline
  151.  *94Sept30 Applied diffs for Fri Aug 26 00:51:20 1994
  152.  *94Sept30 Applied diffs for Tue Aug 30 07:28:05 1994
  153.  *94Oct07 Inserted MW changes
  154.  *94Dec27mm Added in_avail following pjp.
  155.  */
  156.